package BitCreeekClient;

import javax.swing.event.EventListenerList;

import java.awt.Component;
import java.util.EventListener;
import java.util.EventObject;

class GUIEvent extends EventObject {
	private static final long serialVersionUID = 1L;

	public GUIEvent ( Object source ) {
        super ( source );
    }
}

interface GUIEventListener extends EventListener {
    public void guiEventOccurred ( GUIEvent evt );
}

class GUIError extends EventObject {
	private static final long serialVersionUID = 1L;

	public GUIError ( Object source ) {
        super ( source );
    }
}

interface GUIErrorListener extends EventListener {
    public void guiErrorOccurred ( GUIError evt );
}

class GUIHandler {
    protected EventListenerList listenerList = new EventListenerList ();
    protected EventListenerList listenerErrorList = new EventListenerList ();
    
    
    public void addGUIEventListener ( GUIEventListener listener ) {
        listenerList.add ( GUIEventListener.class, listener );
    }

    public void removeGUIEventListener ( GUIEventListener listener ) {
        listenerList.remove ( GUIEventListener.class, listener );
    }
    
    public void addGUIErrorListener ( GUIErrorListener listener ) {
    	listenerErrorList.add ( GUIErrorListener.class, listener );
    }

    public void removeGUIErrorListener ( GUIErrorListener listener ) {
    	listenerErrorList.remove ( GUIErrorListener.class, listener );
    }

    void fireGUIError ( GUIError evt ) {
        Object[] listeners = listenerErrorList.getListenerList ();
        for ( int i = 0; i < listeners.length; i = i + 2 ) {
            if ( listeners[ i ] == GUIErrorListener.class ) {
                ( ( GUIErrorListener ) listeners[ i + 1 ] ).guiErrorOccurred ( evt );
            }
        }
    }
    
    void fireGUIEvent ( GUIEvent evt ) {
        Object[] listeners = listenerList.getListenerList ();
        for ( int i = 0; i < listeners.length; i = i + 2 ) {
            if ( listeners[ i ] == GUIEventListener.class ) {
                ( ( GUIEventListener ) listeners[ i + 1 ] ).guiEventOccurred ( evt );
            }
        }
    }

	public Component getParent() {
		return this.getParent();
	}
}
